# -*- encoding:utf-8 -*-

import unittest
from taobao.TaobaoJsonRestClient import TaobaoJsonRestClient
from taobao.request.UserGetRequest import UserGetRequest
from taobao.response.UserGetResponse import UserGetResponse
from taobao.model.User import User

class ItemApiTest(unittest.TestCase):
    """unit test for User APIs"""
    
    def setUp(self):
        self.client = TaobaoJsonRestClient("http://gw.api.tbsandbox.com/router/rest", "test", "test")
        
    def testUserGet(self):
        """Test API taobao.user.get"""
        request = UserGetRequest()
        self.failUnless( (True == isinstance(request, UserGetRequest) ), "check UserGetRequest type")

        request.setFields("nick,sex,buyer_credit,seller_credit,location.city,location.state,location.country,created,last_visit")
        request.setNick("tbtest5")
        
        response = self.client.UserGet(request)
        self.assertTrue(isinstance(response, UserGetResponse))

        print response.getBody()

        user = response.getItem()
        self.failUnless( (True == isinstance(user, User) ), "check user type")        
        self.failUnless(len(item) > 0 , "total results shoud be greater than 0")
        

    def tearDown(self):
        pass

if __name__ == "__main__":
    unittest.main()
